<template>
  <div class="top">
    <img src="../assets/img/arrow-right-black.png" alt="" />
    <span>我的收获地址</span>
  </div>
  <div class="middle">
    <ul v-for="(item, index) in list" :key="item">
      <li>
        <div>
          <span v-if="item.status == 1" class="moren">默认</span>
          <span class="name">{{ item.name }}</span>
          <span class="phone">{{ item.tel }}</span>
          <img src="../assets/img/del.jpg" class="xiugai" @click="del(index)" />
        </div>
        <div class="address">{{ item.address }}</div>
      </li>
    </ul>
  </div>
  <router-link to="/newAddress" class="bottom">
    <img src="../assets/img/add.png" alt="" />
    <span>添加收获地址</span>
  </router-link>
</template>

<script>
import { getAddressApi } from "../../utils/api";
export default {
  data() {
    return {
      list: [],
    };
  },
  mounted() {
    let token = localStorage.getItem("token");
    // console.log(token);
    //接口
    getAddressApi(token).then((res) => {
      console.log(res.result.resArr); //获取到了返回值
      // this.list = res.result.resArr;
      // let newcityList = [];
      this.list = res.result.resArr.map((item) => ({
        id: item.addressId,
        name: item.getName,
        tel: item.getPhone,
        address: item.address,
        status: item.status,
      }));
      // this.list=newcityList;
      //  console.log(newcityList);
      console.log(this.list);
    });
  },
  methods: {
    del(index) {
      this.list.splice(index, 1);
    },
  },
};
</script>

<style lang="less" scoped>
.top {
  display: flex;
  justify-content: center;
  padding: 12px;
  background-color: #fff;
  position: relative;
  border-bottom: 1px solid #eee;
  img {
    transform: rotate(-180deg);
    width: 20px;
    height: 25px;
    position: absolute;
    left: 14px;
  }
  span {
    font-size: 22px;
    text-align: center;
  }
}
.middle {
  background-color: #fff;
  li {
    height: 80px;
    > div:nth-of-type(1) {
      display: flex;
      padding: 10px;
      align-items: center;
      position: relative;
    }
  }
  .moren {
    width: 45px;
    height: 25px;
    background-color: #fb801d;
    color: #fff;
    border-radius: 12px;
    font-size: 14px;
    text-align: center;
    line-height: 25px;
  }
  .name {
    font-size: 14px;
    margin: 0 10px;
  }
  .phone {
    font-size: 14px;
  }
  .xiugai {
    width: 20px;
    height: 20px;
    position: absolute;
    right: 15px;
  }
  .address {
    margin-left: 12px;
    font-size: 14px;
    margin-top: 10px;
  }
}
.bottom {
  background-color: #fff;
  font-size: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 20px;
  height: 50px;
  img {
    width: 22px;
    height: 22px;
    margin: 0 10px;
  }
  span {
    color: #f48a29;
  }
}
</style>
